﻿using System.IO;
using System.Net;

namespace AvalonEdit.Sample
{
    public class WebPageClass
    {
        public static string GetWebPage(string strUrl)
        {
            //stores the html returned by the server
            string strResult="";

            //build the http request
            var webRequest1 = (HttpWebRequest) WebRequest.Create(strUrl);

            IWebProxy proxy = WebRequest.GetSystemWebProxy();
            proxy.Credentials = CredentialCache.DefaultCredentials;

            webRequest1.Proxy = proxy;
            webRequest1.Method = "GET";
            webRequest1.UserAgent = "Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+.NET+CLR+1.1.4322)";
            webRequest1.Timeout = -1;

            //initiate contact with the server
            var webResponse = (HttpWebResponse) webRequest1.GetResponse();

            //download the HTML
            var response = webResponse.GetResponseStream();
            if (response != null)
                using (var sr = new StreamReader(response))
                {
                    //read the html
                    strResult = sr.ReadToEnd();
                    // Close and clean up the StreamReader
                    sr.Close();
                }

            return strResult;
        }
    }
}

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik, @toddanglin
//Facebook: facebook.com/telerik
//=======================================================
